<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData,
		hasValue
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				initValue:{
					fileList:[],
					fileName:'',
					fileSaveName:'',
					files:[],
					fileKey:"36",
					dir:""
				},
				userCacheKey:'hr-py-temployContractSign-title1-user-cache',
				edit:'',
				exists:""
			})
		},
		methods: {
			getDir(){
				let _that = this
				_that.om.request(
					"uploadFiles/getDir",
					{
						fileKey:_that.initValue.fileKey, //
						fileName:_that.formdata.fileUrl //保存后文件名
					}
				).then(res=>{
					_that.formdata.dir = res.value
				})
			},
			getContractInfo(userId){
				let _that = this
				_that.om.request(
					"temployContractSign/getContractInfo",
					{
						userId:userId
					},
					"post"
				).then(res=>{
					if(res.value)
					_that.$refs.autoform.formdata.origContractEndDate = res.value.contractEndDate
					_that.$refs.autoform.formdata.contractTypeCode = res.value.contractTypeCode
					_that.$refs.autoform.formdata.contractTypeName = res.value.contractTypeName
					_that.$refs.autoform.initSelectIndex("title1","contractTypeCode")
				})
			},
			getContractTypeList(){
				let _that = this
				_that.om.request(
					"dictZero/getListByCode",
					{
						code:"38001"
					},
					"post"
				).then(res=>{
					_that.$refs.autoform.changeEditor("title1","contractTypeCode","data",configSelectData(res,"code","dicname"))
					_that.$refs.autoform.initSelectIndex("title1","contractTypeCode")
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				if(_that.files && _that.files.length >1&& _that.edit !== "true"){
					_that.$refs.autoform.formdata.fileName = _that.files.length + ("个文件")
					_that.$refs.autoform.formdata.fileList = _that.files
				}else if(_that.edit !== "true"){
					_that.$refs.autoform.formdata.fileName = _that.fileName
					_that.$refs.autoform.formdata.fileList = _that.files
					_that.$refs.autoform.formdata.fileUrl = _that.fileSaveName
				}
				uni.getStorage({
					key:_that.userCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata 
							formdata.userId = d.id
							formdata.userName = d.username
							formdata.idCard = d.idcard
							formdata.sexName = d.sexName
							formdata.age = d.age
							_that.getContractInfo(d.id)
							_that.getContractTypeList()
							uni.removeStorage({
								key:_that.userCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if (e.configDataCacheKey) {
					_that.exists = _that.datas.filter((e,i)=>{
						return (i != _that.index)
					}).map(e=>e.id).join(",")
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							if (res.data && Object.prototype.toString.call(res.data) === '[object Array]') {
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								changeEditor("title1", "userId", {
									link: "../../public/pageSearch/pageSearch",
									"linkParam": {
										other: JSON.stringify({
											longs:_that.exists,
											editId:e.fileId
										}),
										namefield: "username",
										searchfield: "q",
										method: "post",
										url: "temployContractSign/getUserList",
										initload: true,
										cachename: _that.userCacheKey
									}
								}, null, _that.autoformdata)
								
								changeEditor("title1","fileUpload",{
									link:"../../public/uploadFile/uploadFile",
									"linkParam":{
										url:"/temployContractSign/uploadFile.do",
										type:"one-on-one",
									}
								},null,_that.autoformdata)
								_that.edit = e.edit
								if(e.edit === "true"){
									this.fileName = _that.formdata.fileName
									this.fileSaveName = _that.formdata.fileUrl
									this.files = _that.formdata.fiels
									_that.getDir() //获取保存文件夹
								}
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>
